#include <iostream>
#include <string>
#include <vector>

// 对字符串进行一次递进操作
std::string progressiveOperation(const std::string& s, int x, int y, const std::vector<char>& f) {
    std::string shifted = s.substr(x) + s.substr(0, x);
    std::string result = shifted;
    for (int i = 0; i < result.length(); ++i) {
        char current = result[i];
        for (int j = 0; j < y; ++j) {
            current = f[current - 'a'];
        }
        result[i] = current;
    }
    return result;
}

// 找到最小的正整数 k 使得对 S 做 k 次递进操作的结果是 T
int findMinK(const std::string& S, const std::string& T, int x, int y, const std::vector<char>& f) {
    std::string current = S;
    int k = 1;
    std::vector<std::string> visited;
    visited.push_back(S);
    while (true) {
        current = progressiveOperation(current, x, y, f);
        if (current == T) {
            return k;
        }
        for (const auto& str : visited) {
            if (current == str) {
                return -1;
            }
        }
        visited.push_back(current);
        ++k;
    }
}

int main() {
    int n, x, y;
    std::cin >> n >> x >> y;
    std::string F;
    std::cin >> F;
    std::vector<char> f(26);
    for (int i = 0; i < 26; ++i) {
        f[i] = F[i];
    }
    std::string S, T;
    std::cin >> S >> T;
    int k = findMinK(S, T, x, y, f);
    std::cout << k << std::endl;
    return 0;
}
